<template>
	<view>
		<view class="fixNickTit">设置真实姓名</view>
		<view class="inpWrap">
			<input class="inp" type="text" placeholder="请输入真实姓名" maxlength="4" v-model="realName" placeholder-class="holdInp">
			<view class="tips spec">注:真实姓名一旦设置成功便不能修改,请如实填写</view>
			<!-- <view class="tips spec indent">若身份为学生便于后期家长通过身份证号查询显示</view> -->
		</view>
		<button class="comBtn" :disabled="isDisabledFlag" @tap="saveRealName">保存</button>
	</view>
</template>

<script>
	import { upSelfRealName } from '@/api/mine/index'
	export default {
		data(){
			return{
				realName:'',
				isDisabledFlag:false
			}
		},
		methods:{
			saveRealName(){
				var reg =  /[^\u4E00-\u9FA5]/g;
				if(this.realName == ''){
					this.util.showToast('真实姓名不能为空');
					return;
				}
				if(this.realName.length == 1){
					this.util.showToast('真实姓名长度至少大于1个字符');
					return;
				}
				if(reg.test( this.realName )){
					this.util.showToast('真实姓名应为中文');
					return;
				}
				this.isDisabledFlag = true;
				var field = { realName:this.realName };
				uni.showLoading({title: '设置中...',mask: true});
				upSelfRealName(field).then(res=>{
					this.util.showToastSuc('修改成功');
					let pages = getCurrentPages();
					let prevPage = pages[pages.length - 2];
					prevPage.$vm.realName = this.realName;
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},1500);
				}).catch(err=>{
					this.isDisabledFlag = false;
					console.log(err)
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/scss/setNickName.scss';
</style>